#pragma once

#include <iostream>
#include <string>
#include <functional>
#include <memory>
#include "Initadd.h"

class Reactor;
class Connection
{
public:
    Connection()
        : _sockfd(-1)
    {
    }
    void Setsocket(int sockfd)
    {
        _sockfd = sockfd;
    }
    int Sockfd()
    {
        return _sockfd;
    }
    void SetEvent(int event)
    {
        _event = event;
    }
    int Event()
    {
        return _event;
    }
    void SetOwner(Reactor *owner)
    {
        _owner = owner;
    }
    Reactor *Getowner()
    {
        return _owner;
    }
    void Append(const std::string &message)
    {
        _inbuffer += message;
    }
    void AppendOut(const std::string &out)
    {
        _outbuffer += out;
    }
    std::string &Inbuffer()
    {
        return _inbuffer;
    }
    std::string &outbuff()
    {
        return _outbuffer;
    }
    bool IsOutBufferEmpty()
    {
        return _outbuffer.empty();
    }
    void DisCardOutString(int n)
    {
        _outbuffer.erase(0, n);
    }
    void Close()
    {
        close(_sockfd);
    }
    virtual void Sender() = 0;
    virtual void Recver() = 0;
    virtual void Excepter() = 0;
    ~Connection()
    {
    }

private:
    int _sockfd;
    std::string _inbuffer;
    std::string _outbuffer;
    IntAddr _peer_addr;

    Reactor *_owner;

    uint32_t _event;
};